package com.guida.config;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * author huge
 */

@WebFilter(filterName = "encodingFilter", urlPatterns = "/*")
public class EonCodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("UTF-8");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }

    /**
     * 上述代码实现了一个编码过滤器，将请求和响应都以UTF-8进行编码，防止乱码
     * @WebFilter 注解在容器启动时将本过滤器加载到程序中
     */
}
